package com.tang.Dao;
import com.tang.pojo.Book;
import java.util.List;
public class BookDao {
    public void insert(Book book){
       BaseDao bd=new BaseDao();
       String sql="insert into t_book(name,price,stock,author,sale,imgPath) values(?,?,?,?,?,?);";
       bd.update(sql,book.getName(),book.getPrice(),book.getStock(),book.getAuthor(),book.getSale(),book.getImgPath());
    }
    public void delete(int id){
        BaseDao bd=new BaseDao();
        String sql="delete from t_book where id=?;";
        bd.update(sql,id);
    }
    public void update(Book book,int id){
        BaseDao bd=new BaseDao();
        String sql="update t_book set name=?,price=?,stock=?,author=?,sale=?,imgPath=? where id=?;";
        bd.update(sql,book.getName(),book.getPrice(),book.getStock(),book.getAuthor(),book.getSale(),book.getImgPath(),id);
    }
    public Book queryABook(int id){
        BaseDao bd=new BaseDao();
        String sql="select * from t_book where id=?;";
        return bd.queryforOne(Book.class,sql,id);
    }
    public List<Book> queryBooks(){
        BaseDao bd=new BaseDao();
        String sql="select * from t_book;";
        return bd.queryforMul(Book.class,sql);
    }
    public Book queryByName(String name){
        BaseDao bd=new BaseDao();
        String sql="select * from t_book where name=?;";
        return bd.queryforOne(Book.class,sql,name);
    }
}
